home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / basics / mfc simpleedit.win / simpleeditmfcview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.7 KB  |  214 lines

  1. // SimpleEdit MFCView.cpp : implementation of the CSimpleEditMFCView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "SimpleEditMFC.h"
  6.  
  7. #include "SimpleEditMFCDoc.h"
  8. #include "SimpleEditMFCView.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CSimpleEditMFCView
  18.  
  19. IMPLEMENT_DYNCREATE(CSimpleEditMFCView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CSimpleEditMFCView, CView)
  22.     //{{AFX_MSG_MAP(CSimpleEditMFCView)
  23.     ON_WM_CREATE()
  24.     ON_WM_DESTROY()
  25.     ON_COMMAND(ID_FILE_NEW, OnFileNew)
  26.     ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
  27.     ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  28.     ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  29.     ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  30.     ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  31.     ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  32.     ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  33.     ON_COMMAND(ID_EDIT_SELECTALL, OnEditSelectall)
  34.     ON_WM_SIZE()
  35.     //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CSimpleEditMFCView construction/destruction
  40.  
  41. CSimpleEditMFCView::CSimpleEditMFCView()
  42. {
  43.     // Create a QuickTime object
  44.     pQuickTime = new CQuickTime;
  45.  
  46. }
  47.  
  48. CSimpleEditMFCView::~CSimpleEditMFCView()
  49. {
  50.     // Destroy the QuickTime object
  51.     if ( pQuickTime ) 
  52.          delete pQuickTime;
  53. }
  54.  
  55. BOOL CSimpleEditMFCView::PreCreateWindow(CREATESTRUCT& cs)
  56. {
  57.     // TODO: Modify the Window class or styles here by modifying
  58.     //  the CREATESTRUCT cs
  59.  
  60.     return CView::PreCreateWindow(cs);
  61. }
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CSimpleEditMFCView drawing
  65.  
  66. void CSimpleEditMFCView::OnDraw(CDC* pDC)
  67. {
  68.     Movie    theMovie;
  69.     CSimpleEditMFCDoc* pDoc = GetDocument();
  70.     ASSERT_VALID(pDoc);
  71.  
  72.     if (theMovie = pQuickTime->GetMovie())
  73.         UpdateMovie(theMovie);
  74. }
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CSimpleEditMFCView diagnostics
  78.  
  79. #ifdef _DEBUG
  80. void CSimpleEditMFCView::AssertValid() const
  81. {
  82.     CView::AssertValid();
  83. }
  84.  
  85. void CSimpleEditMFCView::Dump(CDumpContext& dc) const
  86. {
  87.     CView::Dump(dc);
  88. }
  89.  
  90. CSimpleEditMFCDoc* CSimpleEditMFCView::GetDocument() // non-debug version is inline
  91. {
  92.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSimpleEditMFCDoc)));
  93.     return (CSimpleEditMFCDoc*)m_pDocument;
  94. }
  95. #endif //_DEBUG
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CSimpleEditMFCView message handlers
  99.  
  100. int CSimpleEditMFCView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  101. {
  102.     if (CView::OnCreate(lpCreateStruct) == -1)
  103.         return -1;
  104.     
  105.     // Setup movie window     
  106.      strcpy((char *)pQuickTime->theAppName, AfxGetAppName());  // store app name for window title
  107.  
  108.     pQuickTime->OnMovieWindowCreate( m_hWnd, lpCreateStruct);
  109.     
  110.     return 0;
  111. }
  112.  
  113. void CSimpleEditMFCView::OnDestroy() 
  114. {
  115.     CView::OnDestroy();
  116.     
  117.     // Destroy movie window
  118.     pQuickTime->OnMovieWindowDestroy();
  119. }
  120.  
  121.  
  122. BOOL CSimpleEditMFCView::OpenMovie(void)
  123. {
  124.     return pQuickTime->OpenMovie((unsigned char *)(LPCSTR)mfullPath);
  125. }
  126.  
  127. void CSimpleEditMFCView::CloseMovie(void)
  128. {
  129.     pQuickTime->CloseMovie();
  130. }
  131.  
  132.  
  133. void CSimpleEditMFCView::OnFileNew() 
  134. {
  135.     pQuickTime->NewMovieFile();
  136.     
  137. }
  138.  
  139. void CSimpleEditMFCView::OnFileClose() 
  140. {
  141.     CSimpleEditMFCDoc* pDoc = GetDocument();
  142.  
  143.     pQuickTime->CloseMovie();
  144.  
  145.     pDoc->SetPathName( "Untitled", false );
  146. }
  147.  
  148. void CSimpleEditMFCView::OnFileSaveAs() 
  149. {
  150.     pQuickTime->SaveAsMovie();
  151. }
  152.  
  153. void CSimpleEditMFCView::OnEditUndo() 
  154. {
  155.     pQuickTime->OnEditUndo();
  156.     
  157. }
  158.  
  159. void CSimpleEditMFCView::OnEditCut() 
  160. {
  161.     pQuickTime->OnEditCut();
  162.     
  163. }
  164.  
  165. void CSimpleEditMFCView::OnEditCopy() 
  166. {
  167.     pQuickTime->OnEditCopy();    
  168. }
  169.  
  170. void CSimpleEditMFCView::OnEditPaste() 
  171. {
  172.     pQuickTime->OnEditPaste();
  173. }
  174.  
  175. void CSimpleEditMFCView::OnEditClear() 
  176. {
  177.     pQuickTime->OnEditClear();    
  178. }
  179.  
  180. void CSimpleEditMFCView::OnEditSelectall() 
  181. {
  182.     pQuickTime->OnEditSelectall();    
  183. }
  184.  
  185. LRESULT CSimpleEditMFCView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  186. {
  187.     if(message == WM_ERASEBKGND){
  188.         LRESULT theResult = CView::WindowProc(message, wParam, lParam);
  189.         pQuickTime->ProcessMovieEvent (m_hWnd, message, wParam, lParam);    
  190.         return theResult;
  191.     } else {
  192.         pQuickTime->ProcessMovieEvent (m_hWnd, message, wParam, lParam);
  193.         return CView::WindowProc(message, wParam, lParam);
  194.     }
  195. }
  196.  
  197. void CSimpleEditMFCView::OnSize(UINT nType, int cx, int cy) 
  198. {
  199.     CView::OnSize(nType, cx, cy);
  200.     if (cy && cx)
  201.     {
  202.         // calculate the size of the frame
  203.         CFrameWnd* pFrame = GetParentFrame();
  204.         if (pFrame != NULL)
  205.         {
  206.             CRect rectSized(0, 0, cx, cy);
  207.             pFrame->CalcWindowRect(rectSized);
  208.             pFrame->SetWindowPos(this,0,0,rectSized.Width() + 4,rectSized.Height()+ GetSystemMetrics(SM_CYMENU) + 4, SWP_NOZORDER | SWP_NOMOVE );
  209.  
  210.         }
  211.     }
  212. }
  213.  
  214.